package com.zbkj.front.controller.employee;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.merchant.Merchant;
import com.zbkj.common.request.merchant.MerchantAddRequest;
import com.zbkj.common.request.merchant.MerchantUpdateRequest;
import com.zbkj.common.response.MerchantBaseInfoResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.token.FrontTokenComponent;
import com.zbkj.service.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @Auther: 大粽子
 * @Date: 2024/5/29 11:14
 * @Description: 描述对应的业务场景
 */
@Slf4j
@RestController
@RequestMapping("api/front/employee/merchant")
@Api(tags = "移动端商家管理 - 商户基础操作") //配合swagger使用
public class EmployeeMerchantController {

    @Autowired
    private FrontTokenComponent tokenComponent;
    @Autowired
    private MerchantService merchantService;

    @ApiOperation(value = "激活当前正在操作的商户")
    @RequestMapping(value = "/active/{id}", method = RequestMethod.GET)
    public CommonResult<String> activeMerchant(@PathVariable(value = "id") Integer id) {
        tokenComponent.activeMerchantEmployee(id);
        return CommonResult.success();
    }

    @ApiOperation(value = "商户端商户基础信息")
    @RequestMapping(value = "/base/info/{systemAdminId}", method = RequestMethod.GET)
    public CommonResult<MerchantBaseInfoResponse> getBaseInfo(@PathVariable(value = "systemAdminId") Integer systemAdminId) {
        return CommonResult.success(merchantService.getBaseInfo(systemAdminId));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.ADD, description = "添加商户")
    @ApiOperation(value="添加商户")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult<Object> add(@RequestBody @Validated MerchantAddRequest request) {
        Merchant merchant = merchantService.xcxAdd(request);
        if (merchant.getIsSave()) {
            return CommonResult.success(merchant);
        }
        return CommonResult.failed("添加商户失败");
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.ADD, description = "添加商户")
    @ApiOperation(value="修改商户")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public CommonResult<Object> add(@RequestBody @Validated MerchantUpdateRequest request) {
        if (merchantService.edit(request)) {
            return CommonResult.success();
        }
        return CommonResult.failed("修改商户失败");
    }
}
